package reduce.fz.com.reduce.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;

import reduce.fz.com.reduce.custom.pagerheader.ScrollableFragmentListener;
import reduce.fz.com.reduce.custom.pagerheader.ScrollableListener;
import reduce.fz.com.reduce.fragment.base.BaseFragment;


public abstract class BaseViewPagerFragment extends BaseFragment implements ScrollableListener {

    protected static ScrollableFragmentListener mListener;
    public  static final String BUNDLE_FRAGMENT_INDEX = "BaseFragment.BUNDLE_FRAGMENT_INDEX";
    protected int mFragmentIndex;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();

        if (bundle != null) {
            mFragmentIndex = bundle.getInt(BUNDLE_FRAGMENT_INDEX, 0);
        }

        if (mListener != null) {
            mListener.onFragmentAttached(this, mFragmentIndex);
        }
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
    }

    public static void setListener(ScrollableFragmentListener sl){
        mListener =  sl;
    }

    @Override
    public void onDetach() {
        if (mListener != null) {
            mListener.onFragmentDetached(this, mFragmentIndex);
        }

        super.onDetach();
        mListener = null;
    }
    public boolean isViewBeingDragged(MotionEvent event)
    {
        return false;
    }
}
